home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: netcom.com!marnold
- From: marnold@netcom.com (Matt Arnold)
- Subject: Re: Is there a standard for * and & placement style?
- Message-ID: <marnoldDn63vB.H6n@netcom.com>
- Organization: NETCOM On-line Communication Services (408 261-4700 guest)
- References: <3128BD31.4AF8@wildfire.com> <marnoldDn27q9.Is0@netcom.com> <4gckd5$bc7@clarknet.clark.net>
- Date: Thu, 22 Feb 1996 08:06:46 GMT
- Sender: marnold@netcom10.netcom.com
-
- gusty@clark.net (Harlan Messinger) writes:
-
- >Matt Arnold (marnold@netcom.com) wrote:
- >: My personal preference is Form 1, and I have a logical reason: It
- >: seems to me that that "pointer-ness" (*) or "reference-ness" (&) is
- >: certinaly part of the variable *type*, not part of the variable. It
- >: therefore seems logical to associate * or & with type identifier
- >: rather than the variable name. For me, this creates a distinct
- >: visual separation between types and variables.
-
- >I agree with you that I would _like_ the * and the & to be appended to
- >the base type. However, the syntax of pointer and reference type
- >declarations itself associates the * and the & with the variable names,
- >as can be seen when multiple variables are declared on the same line.
-
- > char* p, q;
-
- As a rule, I never declare multiple variables on one line. I prefer to
- program so that each line (if possible) only deals with a single concept.
- A single branch, a single function call, a single variable declaration,
- etc.. I dislike the ? operator, if you see what I mean, although I use
- it occasionally.
-
- Anyway, never writing something like the above declaraion of p and q is
- due to this rule I use.
-
- >may appear to declare two variables, each a (char*), but that is not the
- >case. Instead, p is (char*) and q is char. To get both of them to be
- >(char*), we need
-
- > char *p, *q;
-
- >Adding more complexity,
-
- > char a, b, *c, *d, &e = a;
-
- >declares a and b as char, c and d as (char*), and e as (char&).
-
- Yuck! This kind of confusion is exactly why I don't use such forms.
-
- >I think the syntax is dumb in the first place. One declaration statement
- >should declare variables of one type. I think
-
- > char* a, b, c;
-
- >should declare three (char*) variables. If someone also wants a char
- >variable d, then that should be on two lines:
-
- That would be better, but I still subscribe to the "one concept per
- line" theory of programming and would never declare three variables on
- a single line.
-
- I'd prefer...
-
- char* a;
- char* b;
- char c;
- char& d;
-
- ...to any other way. You simply can't make a mistake, misinterpret
- or confuse variable declarations with this format as you can with the
- others.
-
- Some may think "one concept per line" to be silly, but I've found it
- also makes maintaining code a bit simpler (for less intra-line edits,
- and more line-by-line edits). Output of diff programs is also less
- cluttered.
-
- Just because the langauge allows a particular syntax does not mean
- you have to use it or structure your coding practices around it. I
- simply don't use mutli-variable declarations and considerations like
- you point out above have never been a source of trouble for me.
-
- Regards,
- -------------------------------------------------------------------------
- Matt Arnold | | ||| | |||| | | | || ||
- marnold@netcom.com | | ||| | |||| | | | || ||
- Boston, MA | 0 | ||| | |||| | | | || ||
- 617.389.7384 (h) 617.576.2760 (w) | | ||| | |||| | | | || ||
- C++, MIDI, Win32/95 developer | | ||| 4 3 1 0 8 3 || ||
- -------------------------------------------------------------------------
-
-
-
-